//
//  STAddIdeaView.swift
//  SlowTrajectory
//
//  Created by iOS-Czz on 2023/10/23.
//

import UIKit

class STAddIdeaView: UIView {
    @IBOutlet var bgView: UIView!
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    var onSave: (() -> Void)?

    @IBOutlet var contentTV: UITextView!
    @IBOutlet var dayLabel: UILabel!
    override  func awakeFromNib() {
        super.awakeFromNib()
        self.bgView.addDashedBorder(color: .black, lineWidth: 1, cornerRadius: 15)
        self.contentTV.addPlaceholder("请输入想法")

    }
    var model: STLogsModel? {
        didSet {
            self.dayLabel.text = model!.day + " " + model!.weekday
        }
    }
    @IBAction func clickCloseAction(_ sender: Any) {
        self.removeFromSuperview()
    }
    @IBAction func saveAction(_ sender: Any) {
        if self.contentTV.text!.isEmpty {
            UIView.showTipsView("请输入想法")
            return
        }
        model?.idea = self.contentTV.text
        model?.updateToDB()
        onSave?()
        self.removeFromSuperview()
    }
}
